<?php
/**
 * @brief recovery_en protocol
 *
 * @param post uid User ID
 * @return True/False (True : cash, en)
 * @author con100 <con100@playplus.net>
 * @since 05/04/2013
 * @copyright Copyright (c) 2013, PlayPlus
 **/

include 'dbconn.php';
include 'config.php';

$user_id = mysql_real_escape_string($_POST['uid']);

$sql = "select en, max_en, timestemp_en, cash from ebs_member where id='$user_id'";
$res = mysql_query($sql);
$data = mysql_fetch_assoc($res);

$time_en = (int)($data['en']+(time()-$data['timestemp_en']) * $en_sec);
$data['en'] = min($time_en, $data['max_en']);

if($$data['en']< $data['max_en'] && $pay_recovery_en <= $data['cash']){
	$data['en'] = $data['max_en'];
	$data['cash'] -= $pay_recovery_en;
	$sql = "update ebs_member set en='$data[en]', cash='$data[cash]' where id='$user_id'";
	$res = mysql_query($sql);
	$result = array("Result"=>TRUE, "cash"=>$data['cash'], "en"=>$data['en']);

}
else{
	$result = array("Result"=>FALSE);
}
echo json_encode($result);
/*
header('Content-type: text/xml; charset=UTF-8');

$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(true);
$writer->setIndentString('  ');
$writer->startDocument('1.0', 'UTF-8');

$writer->startElement('recovery_en');
	$writer->startElement('result');
	$writer->text($result);
	$writer->endElement();
	if($result == "TRUE"){
		$writer->startElement('cash');
		$writer->text($cash);
		$writer->endElement();
	}
$writer->endElement();

echo($writer->outputMemory());
*/
?>